package com.fingard.dsp.bank.directbank.wjzf02;

import java.util.ArrayList;
import java.util.Arrays;

import com.fingard.dsp.bank.directbank.DirectBase;
import com.fingard.xml.XmlTextWriter;

public class WJZF02Base extends DirectBase {
	protected String getCharset(){
		return getBankConfig().getCharset("GBK");
	}
	
	protected void writeCommonHeader(XmlTextWriter xmlWriter,WJZF02Header header) throws Exception{
		xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\""+getCharset()+"\"?>");
		xmlWriter.writeStartElement("Message");
		xmlWriter.writeStartElement("Head");
		xmlWriter.writeElementString("CorpNo", header.CorpNo);
		xmlWriter.writeElementString("Version", header.Version);
		xmlWriter.writeElementString("TranCode", header.TranCode);
		xmlWriter.writeElementString("FeeNo", header.FeeNo);
		xmlWriter.writeEndElement();
	}
	
	protected static ArrayList<ArrayList<String>> spitXml(String returnXml) {
		ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>();

		String[] splitStrs = returnXml.split("\n");
		for (String splitStr : splitStrs) {
			splitStr = splitStr.trim();
			/*
			 * if (!(splitStr.startsWith("{") && splitStr.endsWith("}"))) {
			 * throw new Exception("返回的数据有问题"); }
			 */
			if (splitStr.contains("{") && splitStr.contains("}")) {
				splitStr = splitStr.substring(1, splitStr.length() - 2);
			}
			ArrayList<String> tempList = new ArrayList<String>(Arrays.asList(splitStr.split("\\|")));
			result.add(tempList);
		}

		return result;
	}
}
